//
//  VKAboutAppController.m
//  V-Learn
//
//  Created by liubo on 2019/1/14.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKAboutAppController.h"
#import "VKServerXYController.h"
#import "VKServerXYListController.h"
@interface VKAboutAppController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation VKAboutAppController
-(UITableView *)tableView{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen cz_screenWidth], [UIScreen cz_screenHeight] - LBNAVBAR_HEIGHT) style:UITableViewStyleGrouped];
        _tableView.tableFooterView = [UIView new];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 56;
        [self.view addSubview:_tableView];
        _tableView.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
    self.edgesForExtendedLayout = @[];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.title = @"关于APP";
    [self tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen cz_screenWidth], 195)];
        view.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
        
        UIImageView *imageV = [[UIImageView alloc]init];
        [view addSubview:imageV];
        imageV.image = [UIImage imageNamed:@"v"];
        [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@90);
            make.centerX.equalTo(view);
            make.top.mas_equalTo(@60);
        }];
        
        UILabel *versionLabel = [[UILabel alloc]init];
        [view addSubview:versionLabel];
        versionLabel.textColor = [UIColor cz_colorWithRed:253 green:79 blue:83];
        versionLabel.text = @"V2.0";
        [versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(view);
            make.top.mas_equalTo(imageV.mas_bottom).offset(10);
        }];

        return view;
    }
    
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 195;
    }
    return 0.1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        UILabel *titleLabel = [[UILabel alloc]init];
        [cell.contentView addSubview:titleLabel];
        titleLabel.textColor = [UIColor cz_colorWithRed:51 green:51 blue:51];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@15);
            make.centerY.equalTo(cell.contentView);
        }];
        if (indexPath.row == 0) {
            titleLabel.text = @"去评分";
            UIView *lineView = [[UIView alloc]init];
            [cell.contentView addSubview:lineView];
            lineView.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.equalTo(@0);
                make.height.equalTo(@1);
                make.bottom.mas_equalTo(cell.contentView);
            }];
        }else if (indexPath.row == 1){
            titleLabel.text = @"服务协议";
        }
        UIImageView *arrowImageV = [[UIImageView alloc]init];
        arrowImageV.image = [UIImage imageNamed:@"left"];
        [cell.contentView addSubview:arrowImageV];
        [arrowImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.centerY.mas_equalTo(cell.contentView);
        }];
        
        
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row==0) {
        //跳转去评分页面
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=1465567470&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"]];
        NSString *str = [NSString stringWithFormat:
                         @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@",
                         @"1465567470"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }
    if (indexPath.row == 1) {
        [self.navigationController pushViewController:[[VKServerXYListController alloc]init] animated:YES];
    }
}

@end
